package magis;

import edu.byu.intex2.data.bo.Sale;
import edu.byu.intex2.data.bo.TradeInLine;
import javax.swing.table.*;

/**
 * Trade In Line JTable Table Model
 * Displays Actual Price, List Price, VIN, and Color
 * @author Brady White
 */
public class TradeInLineTableDataModel extends AbstractTableModel {

    Sale sale = null;

    public TradeInLineTableDataModel(Sale sale) {
        this.sale = sale;
    }

    public int getRowCount() {
        return sale.getTradeInLines().size();
    }

    public int getColumnCount() {
        return 4;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        // Go through columnIndex and assign respective attributes to the columns
        TradeInLine tradeInLine = sale.getTradeInLines().get(rowIndex);

        try { 
            switch (columnIndex) {
                case 0:
                    return tradeInLine.getTradeInValue();
                case 1:
                    return tradeInLine.getUsedCar().getVin();
                case 2:
                    return tradeInLine.getMileage();
                case 3:
                    return tradeInLine.getUsedCar().getCarCondition();
                default:
                    return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /** Allow user to edit cells but first column  */
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    /** @return TradeInLine from rowIndex */
    public TradeInLine getTradeInLine(int rowIndex){
        return sale.getTradeInLines().get(rowIndex);
    }
}
